﻿//-----------------------------------------------------------------------
// <copyright file="IDataBag.cs" company="Nathan Miller">
// Copyright (c) Nathan Miller.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//-----------------------------------------------------------------------
namespace TileTool.DataBag
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using TileTool.DataBag.Generic;

    /// <summary>
    /// Data bag interface
    /// </summary>
    public interface IDataBag : IEnumerable<KeyValuePair<string, IDataBagValue>>, IEnumerable
    {
        #region Events

        /// <summary>
        /// Event triggered when a data bag value changes.
        /// 
        /// First parameter is the data bag that contains the value.
        /// Second parameter is the value that changed.
        /// </summary>
        event Action<IDataBag, IDataBagValue> Changed;

        #endregion

        #region Properties

        /// <summary>
        /// Gets a collection containing the keys of the dictionary.
        /// </summary>
        ICollection<string> Keys
        {
            get;
        }

        /// <summary>
        /// Gets a collection containing the values of the dictionary.
        /// </summary>
        ICollection<IDataBagValue> Values
        {
            get;
        }

        /// <summary>
        /// Gets the number of elements
        /// </summary>
        int Count
        {
            get;
        }

        /// <summary>
        /// Gets or sets the element with the specified key.
        /// </summary>
        /// <param name="key">Key to get.</param>
        /// <returns>Returns the value associated with key.</returns>
        IDataBagValue this[string key]
        {
            get;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Clone this data bag by creating a deep copy.
        /// </summary>
        /// <returns>Returns a copy of the data bag.</returns>
        IDataBag Clone();

        /// <summary>
        /// Determines if the data bag contains the key.
        /// </summary>
        /// <param name="key">Key to locate.</param>
        /// <returns>Returns true if the dictionary contains the key.</returns>
        bool ContainsKey(string key);

        /// <summary>
        /// Gets the value associated with the specified key.
        /// </summary>
        /// <param name="key">The key whose value to get.</param>
        /// <param name="value">When this method returns, the value associated with the specified key,
        /// if the key is found; otherwise, the default value for the type of the value parameter.
        /// This parameter is passed uninitialized.</param>
        /// <returns>true if the object is found.</returns>
        bool TryGetValue(string key, out IDataBagValue value);

        /// <summary>
        /// Gets the value associated with the specified key.
        /// </summary>
        /// <typeparam name="T">Type of value to get.</typeparam>
        /// <param name="key">The key whose value to get.</param>
        /// <param name="value">When this method returns, the value associated with the specified key,
        /// if the key is found; otherwise, the default value for the type of the value parameter.
        /// This parameter is passed uninitialized.</param>
        /// <returns>true if the object is found.</returns>
        bool TryGetValue<T>(string key, out IDataBagValue<T> value);

        /// <summary>
        /// Convert the data bag to a dictionary which contains only strings.
        /// 
        /// The key to the dictionary is the name of the value.
        /// The value in the dictionary is an array of two strings. The first string is the type
        /// of data bag value and the second string is the data bag value in string form.
        /// </summary>
        /// <returns>Returns the databag as a dictionary of strings.</returns>
        IDictionary<string, string[]> ToStringDictionary();

        #endregion
    }
}
